﻿using System;
using System.CodeDom.Compiler;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Microsoft.CSharp;

namespace JH.GladeSharpCodeGenerator
{
    [ComVisible(true)]
    [Guid("C5A81149-54CD-43da-B084-719E6FC8A520")]
    public class CSGeneratorFromGlade : GeneratorFromGlade
    {
        private CodeDomProvider _codeProvider = new CSharpCodeProvider();
        protected override CodeDomProvider CodeProvider
        {
            get { return _codeProvider; }
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (_codeProvider != null)
            {
                _codeProvider.Dispose();
                _codeProvider = null;
            }
        }

        #region Registration

        private static readonly Guid CustomToolGuid = new Guid("{C5A81149-54CD-43da-B084-719E6FC8A520}");

        private static readonly Guid Category = new Guid("{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}");

        private const string CustomToolDescription = "C# code generator for glade";

        [ComRegisterFunction]
        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "t", Justification = "Signature is imposed by COM")]
        private static void RegisterClass(Type t)
        {
            Register(new Version(9, 0), Category, CustomToolGuid, CustomToolName, CustomToolDescription);
        }

        [ComUnregisterFunction]
        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "t", Justification = "Signature is imposed by COM")]
        private static void UnregisterClass(Type t)
        {
            Unregister(new Version(9, 0), Category, CustomToolName);
        }

        #endregion
    }
}
